package com.vsked.util;

public class Symbol {
	public static String enterSymbol="\n";
	public static String forDaoEditMethodPrimaryKey="";
	public static String delChar=",";
	public static String getStringFirstUpperCase(String inStr){
		return replaceSymbol((inStr.substring(0,1).toUpperCase()+inStr.substring(1)));				
	}
	public static String getStringFirstLowerCase(String inStr){
		return replaceSymbol((inStr.substring(0,1).toLowerCase()+inStr.substring(1)));				
	}
	public static String replaceSymbol(String inStr){
		return inStr.replace("_", "");
	}

	public static String getSpaceString(int inNum){
		String spaceString="";
		for(int i=0;i<inNum;i++)
			spaceString+=" ";
		return spaceString;
	}
	public static String[] getStringTOStringArray(String inString,String inSplitSymbol){
		return inString.split(inSplitSymbol);		
	}
	public static String getStringArrayToString(String[] inStringArray,String inSplitSymbol){
		String tempStr="";
		for(int i=0;i<inStringArray.length;i++)
			tempStr="".equals(tempStr)?inStringArray[i]+inSplitSymbol:tempStr+inStringArray[i]+inSplitSymbol;
		return tempStr;
	}
	public static String getDAOParameterRegString(String[] inParameterArray,String inTableName){
		String tempStr="";
		for(int i=0;i<inParameterArray.length;i++){
			String inColumnName=inParameterArray[i].split("#")[0];
			String inColumnDataType=inParameterArray[i].split("#")[1];
			tempStr+=Symbol.enterSymbol+Symbol.getSpaceString(8)+"pt.set"+Symbol.getStringFirstUpperCase(inColumnDataType)+"("+(i+1)+",in"+Symbol.getStringFirstUpperCase(inTableName)+".get"+Symbol.getStringFirstUpperCase(inColumnName)+"());";
		}
		return tempStr;
	}
	public String getAddSql(String[] inParameterArray,String inTableName){
		BeanProcess.addConsructString=BeanProcess.getContructFromArray(inTableName, inParameterArray);
		String sqlStart="insert into "+inTableName+"(";
		String columnList="";
		String valueList=" values(";
		for(int i=0;i<inParameterArray.length;i++){
			String inColumnName=inParameterArray[i].split("#")[0];
			String inColumnDataType=inParameterArray[i].split("#")[1];
			columnList="".equals(columnList)?inColumnName:columnList+","+inColumnName;
			valueList=" values(".equals(valueList)?valueList+"?":valueList+",?";
			ServletProcess.forServletAddParmReg+="int".equals(inColumnDataType.trim())?Symbol.enterSymbol+Symbol.getSpaceString(8)+inColumnDataType+Symbol.getSpaceString(1)+Symbol.getStringFirstLowerCase(inColumnName)+"=Integer.parseInt(request.getParameter(\""+Symbol.getStringFirstLowerCase(inColumnName)+"\"));":Symbol.enterSymbol+Symbol.getSpaceString(8)+inColumnDataType+Symbol.getSpaceString(1)+Symbol.getStringFirstLowerCase(inColumnName)+"=request.getParameter(\""+Symbol.getStringFirstLowerCase(inColumnName)+"\");";
			BeanProcess.addNewObjectInParmForServlet="".equals(BeanProcess.addNewObjectInParmForServlet)?Symbol.getStringFirstLowerCase(inColumnName):BeanProcess.addNewObjectInParmForServlet+","+Symbol.getStringFirstLowerCase(inColumnName);
		}
		
		columnList+=")";
		valueList+=")";
		return "\""+sqlStart+columnList+valueList+"\"";
	}
	public String getEditSql(String[] inParameterArray,String inTableName,String inPrimaryKey,String inPrimaryKeyDatatype){
		BeanProcess.editConsstructString=BeanProcess.getContructFromArray(inTableName, inParameterArray);
		String sqlStart="update "+inTableName+" set ";
		String columnList="";
		for(int i=0;i<inParameterArray.length;i++){
			String inColumnName=inParameterArray[i].split("#")[0];
			String inColumnDataType=inParameterArray[i].split("#")[1];
			columnList="".equals(columnList)?inColumnName+"=?":columnList+","+inColumnName+"=?";
			ServletProcess.forServletEditParReg+="int".equals(inColumnDataType.trim())?Symbol.enterSymbol+Symbol.getSpaceString(8)+inColumnDataType+Symbol.getSpaceString(1)+Symbol.getStringFirstLowerCase(inColumnName)+"=Integer.parseInt(request.getParameter(\""+Symbol.getStringFirstLowerCase(inColumnName)+"\"));":Symbol.enterSymbol+Symbol.getSpaceString(8)+inColumnDataType+Symbol.getSpaceString(1)+Symbol.getStringFirstLowerCase(inColumnName)+"=request.getParameter(\""+Symbol.getStringFirstLowerCase(inColumnName)+"\");";
			BeanProcess.editNewObjectInParmForServlet="".equals(BeanProcess.editNewObjectInParmForServlet)?Symbol.getStringFirstLowerCase(inColumnName):BeanProcess.editNewObjectInParmForServlet+","+Symbol.getStringFirstLowerCase(inColumnName);
		}
		forDaoEditMethodPrimaryKey="pt.set"+Symbol.getStringFirstUpperCase(inPrimaryKeyDatatype)+"("+(inParameterArray.length+1)+",in"+Symbol.getStringFirstUpperCase(inTableName)+".get"+Symbol.getStringFirstUpperCase(inPrimaryKey)+"());"+Symbol.enterSymbol+Symbol.getSpaceString(8);
		return "\""+sqlStart+columnList+Symbol.getSpaceString(1)+"where "+inPrimaryKey+"=?"+"\"";
	}
	
	public static String getAlign(int inAlign){
		String alignStr="left";
		switch(inAlign){
		case 0: alignStr="left"; break;
		case 1: alignStr="center"; break;
		case 2: alignStr="right"; break;
		}
		return alignStr;
	}
	
	public static void cleanAllStaticData(){
		BeanProcess.addConsructString="";
		BeanProcess.addNewObjectInParmForServlet="";
		BeanProcess.editConsstructString="";
		BeanProcess.editNewObjectInParmForServlet="";
		BeanProcess.forDAOInfoMethodString="";
		
		ServletProcess.forServletAddParmReg="";
		ServletProcess.forServletEditParReg="";
		
		Symbol.forDaoEditMethodPrimaryKey="";
	}
	public static void main(String[] args) {
		String pStr="AreaPostCode#String&AreaName#String&ParentAreaId#int&AreaMemo#String";
		String[] pArray=Symbol.getStringTOStringArray(pStr, "&");
		System.out.println(new Symbol().getEditSql(pArray, "Tb_Area","AreaId","int"));
		System.out.println(Symbol.forDaoEditMethodPrimaryKey);
		
		
	}
}
